<template>
	<view class="pages">
		<view class="form">
			<view class="inp" >
				<text>资金账户可用余额</text>
				<view class="">
					<text style="font-weight: 600;font-size: 32rpx;color: #333333;">¥ {{money}}</text>
				</view>		
			</view>
		</view>
		
		<view class="form">
			 
			<view class="inp">
				<text>提现金额</text>
				<view class="">
					<input v-model="form.money" type="digit" :placeholder="'当前可提现余额 ¥'+money"/>
					 
				</view>
			</view>
			<view class="inp">
				<text>退款原因</text>
				<view class="flex" @click="$refs.reason.visible=true">
					<text v-if="form.reason">{{form.reason }}</text>
					<text v-else style="color: #666;">  请选择原因 </text>
					<u-icon name="arrow-right" color="#666" size="15"></u-icon>
				</view>
			</view>
			<view class="inp">
				<text>退款说明</text>
				<view class="">
					<input v-model="form.remak" type="text" placeholder="退款说明(选填)"/>
					 
				</view>
			</view>
			
			<view class="txt">
				<rich-text :nodes="content"></rich-text>
			</view>
		</view>
			
		<reason-list @handleChange="handleChange" ref="reason" dict="refund_reason"></reason-list>
		 
		<view class="footer">
			<view class="btn" @click="handleCash">
				申请提现
			</view>
		</view>
	</view>
</template>

<script>
	import {noticeInfoAPI,noticelistAPI} from "@/api/appointment.js"
	import { userInfoAPI,updateuserInfoAPI,getwalletAPI,transfercreateAPI,transfersubmitAPI} from "@/api/user.js"
	import pro from "@/utils/uploadImg.js"
	import { uploadtempFile } from "@/utils/upload.js"
	import reasonList from "../components/reasonList.vue"
 	export default {
		components:{
			 reasonList
		},
		data() {
			return {
				form: {
					reason:''
				},
				money:"123.22",
				show:false,
				wallet:{
					
				},
				content: '',
				info:{}
			}
		},
		created() {
			this.getwallet()
			this.noticeInfo()
		},
		onLoad(option) {
			
			 
		},
		methods: {
			noticeInfo(){
				noticeInfoAPI({id:'29'}).then(res=>{
					this.content=res.content;
				})
			},
			getwallet(){
				userInfoAPI().then(res => {
					this.info = res
				})
				getwalletAPI().then(res=>{
					this.wallet=res
					this.money=res.balance
				})
			},
			handleChange(reason){
				console.log(reason.join(","))
				this.form.reason=reason.join(",")
			} ,
			handleCash() {
				if(this.form.money>this.money){
					return uni.showToast({
						title:"提现余额不足",
						icon:"none"
					})
				}
				if(!this.form.reason){
					return uni.showToast({
						title:"请输入退款原因",icon:"none"
					})
				}
				uni.showLoading({
					title:'提交申请中...'
				})
				transfercreateAPI({
					"type": 2,
					"price": this.form.money,
					"payeeInfo": {'openid':uni.getStorageSync('openid')},
					"nickName": this.info.nickname,
					returnReason:this.form.reason,
					returnRemarks:this.form.remak,
				}).then(res=>{
					transfersubmitAPI({
						"id": res,
						"channelCode": "wx_lite",
						"appId":"wx717f725adef874a9",
						"channelExtras": {
							 'openid':uni.getStorageSync('openid')
						}
					}).then(result=>{
						setTimeout(()=>{
							 
							uni.hideLoading()						
							uni.redirectTo({
								url:'/pages/my/integral/applyResult?id='+result.outTransferNo
							})
							 
						},3000)
					})
				})
				 
			}, 
		 }
	}
</script>

<style lang="scss" scoped>
	.pages {
		background-color: #F8F8F8;
		margin-bottom: 100rpx;
		min-height: 100vh;
	}

 
	.form {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 20rpx 30rpx;
		margin-top: 20rpx;

		.inp {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 20rpx 0;

			>text {
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				line-height: 33rpx;
				
			}

			>view {

				image {
					width: 40rpx;
					height: 40rpx;
					margin: 0 10rpx;
				}

				input {
					text-align: right;
				}
			}

		}
	
		.txt{
			font-weight: 400;
			font-size: 24rpx;
			color: #999999;
			line-height: 38rpx;
			margin-top: 30rpx;
			padding-top: 30rpx;
			border-top: 1rpx solid #EEEEEE;
		}
	}

</style>